package initialize

import (
	"github.com/gin-gonic/gin"
	"github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	_ "guns-go/docs"
	"guns-go/global"
	"guns-go/middleware"
	"guns-go/router"
)

func Routers() *gin.Engine {

	var Router = gin.Default()

	Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	global.GVA_LOG.Info("register swagger handler")

	PublicGroup := Router.Group("")

	{
		router.InitBaseRouter(PublicGroup)
	}

	PrivateGroup := Router.Group("")
	PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.OperationLogRecord()).Use(middleware.CasbinHandler())
	{
		router.InitUserRouter(PrivateGroup)
		router.InitDictTypeRouter(PrivateGroup)
		router.InitSysOrgRouter(PrivateGroup)
		router.InitSysPosRouter(PrivateGroup)
		router.InitSysRoleRouter(PrivateGroup)
		router.InitSysFileInfoRouter(PrivateGroup)
		router.InitSysAppRouter(PrivateGroup)
		router.InitSysConfigRouter(PrivateGroup)
		router.InitSysMenuRouter(PrivateGroup)
		router.InitDictDataRouter(PrivateGroup)
		router.InitSysSmsRouter(PrivateGroup)
		router.InitSysOpLogRouter(PrivateGroup)
		router.InitSysVisitLogRouter(PrivateGroup)
		router.InitSysNoticeRouter(PrivateGroup)
		router.InitSysOnlineUserRouter(PrivateGroup)
		router.InitSysSystemRouter(PrivateGroup)
		router.InitEmailRouter(PrivateGroup)
	}

	//资源搜集器，将项目中所有接口都搜集起来
	registerAllResources()

	return Router
}

func registerAllResources() {

	resources := make([]string, 0)

	resources = append(resources, "/login")
	resources = append(resources, "/sysFileInfo/preview")
	resources = append(resources, "/getLoginUser")
	resources = append(resources, "/sysUser/page")
	resources = append(resources, "/sysUser/detail")
	resources = append(resources, "/sysUser/resetPwd")
	resources = append(resources, "/sysUser/ownRole")
	resources = append(resources, "/sysUser/ownData")
	resources = append(resources, "/sysUser/delete")
	resources = append(resources, "/sysUser/add")
	resources = append(resources, "/sysUser/edit")
	resources = append(resources, "/sysUser/grantRole")
	resources = append(resources, "/sysUser/grantData")
	resources = append(resources, "/sysUser/changeStatus")
	resources = append(resources, "/sysUser/updateInfo")
	resources = append(resources, "/sysUser/updatePwd")
	resources = append(resources, "/sysUser/updateAvatar")
	resources = append(resources, "/sysDictType/tree")
	resources = append(resources, "/sysDictType/dropDown")
	resources = append(resources, "/sysOrg/tree")
	resources = append(resources, "/sysOrg/list")
	resources = append(resources, "/sysOrg/page")
	resources = append(resources, "/sysOrg/add")
	resources = append(resources, "/sysOrg/edit")
	resources = append(resources, "/sysOrg/delete")
	resources = append(resources, "/sysPos/list")
	resources = append(resources, "/sysPos/add")
	resources = append(resources, "/sysPos/edit")
	resources = append(resources, "/sysPos/delete")
	resources = append(resources, "/sysPos/page")
	resources = append(resources, "/sysRole/page")
	resources = append(resources, "/sysRole/add")
	resources = append(resources, "/sysRole/edit")
	resources = append(resources, "/sysRole/delete")
	resources = append(resources, "/sysRole/grantMenu")
	resources = append(resources, "/sysRole/grantData")
	resources = append(resources, "/sysRole/ownMenu")
	resources = append(resources, "/sysRole/ownData")
	resources = append(resources, "/sysFileInfo/upload")
	resources = append(resources, "/sysFileInfo/page")
	resources = append(resources, "/sysFileInfo/download")
	resources = append(resources, "/sysFileInfo/delete")
	resources = append(resources, "/sysApp/add")
	resources = append(resources, "/sysApp/edit")
	resources = append(resources, "/sysApp/delete")
	resources = append(resources, "/sysApp/page")
	resources = append(resources, "/sysApp/setAsDefault")
	resources = append(resources, "/sysApp/list")
	resources = append(resources, "/sysMenu/list")
	resources = append(resources, "/sysMenu/tree")
	resources = append(resources, "/sysMenu/add")
	resources = append(resources, "/sysMenu/edit")
	resources = append(resources, "/sysMenu/delete")
	resources = append(resources, "/sysMenu/treeForGrant")

	global.GVA_ROUTER = resources
}
